#!/bin/ksh
#(C) COPYRIGHT International Business Machines Corp. 1991, 1992, 1993, 1996.
# All Rights Reserved.  Licensed Materials - Property of IBM
#####################################################################
# Note: The Config program looks for the file helvR14*.Z in
#       directory /usr/lib/X11/fonts/75dpi .  If this file is not
#       present in the directory then the Config program will not be
#       activated.
#####################################################################
 
args="$*"
batchFlag=false
displayHelp=false
if [ $# != 0 ]; then
     firstArg=$1
     if [ $firstArg = -batch ]; then
          batchFlag=true
          shift
          argShiftedArgs="$*"
     else if [[ $firstArg = -help || $firstArg = /help  ||
                $firstArg = -?    || $firstArg = /?     ||
                $firstArg = ? ]]; then
               displayHelp=true
          fi
     fi
fi
count=0
 
#####################################################################
# Check if we have helvetica 14-point installed in the X11 font
# directories.  Write the command line arguments into the file,
# cfgargs.  The Configuration program will read it and then
# delete it when it comes up.  Invoke the Configuration program
# in the current directory.
function processit {
#   if [ -f /usr/lib/X11/fonts/75dpi/helvR14.snf.Z ]; then
   if [ -n "$(ls -l /usr/lib/X11/fonts/75dpi/helvR14*.Z)" ]; then
       if [ $displayHelp = true ]; then
            more batch.txt
            exit 0
       fi
       if [ $batchFlag = true ]; then
            ./cfg.aix headless.app $argShiftedArgs
       else
            ./cfg.aix cfg.app $args  &
       fi
   fi
exit 0
}
 
#####################################################################
# Check if the files cfg.aix cfg.app, cfg.hlp, cfg.msg and cfg.lgo are 
# installed.  If not then display an error message and exit.
# Also make sure the current directory is writable.
function checkForAppFiles {
 
        if [ ! -w . ]; then
                echo '\007'
                echo 'Cfg error: The current directory is not writable.  Please'
                echo 'either make the current directory writable or copy the'
                echo 'configuration program to a writable directory and try again.'
                exit 1
        fi
        if [ ! -r ./cfg.hlp ]; then
                echo '\007'
                echo 'Cfg error: The file cfg.hlp not be found in the current
directory.'
                echo '  Please re-install the Configuration Program.'
                exit 1
        fi
        if [ ! -r ./cfg.msg ]; then
                echo '\007'
                echo 'Cfg error: The file cfg.msg not be found in the current
directory.'
                echo '  Please re-install the Configuration Program.'
                exit 1
        fi
        if [ ! -r ./cfg.lgo ]; then
                echo '\007'
                echo 'Cfg error: The file cfg.lgo not be found in the current
directory.'
                echo '  Please re-install the Configuration Program.'
                exit 1
        fi
        if [ ! -r ./cfg.aix ]; then
                echo '\007'
                echo 'Cfg error: The file cfg.aix not be found in the current
directory.'
                echo '  Please re-install the Configuration Program.'
                exit 1
        fi
        if [ ! -r ./cfg.app ]; then
                echo '\007'
                echo 'Cfg error: The file cfg.app not be found in the current
directory.'
                echo '  Please re-install the Configuration Program.'
                exit 1
        fi
}
 
 
#####################################################################
# Check if the X11 font files for 14-point helvetica, times and new
# century schoolbook are installed.  If not display an error message
# and exit.
if [ -d /usr/lib/X11/fonts/75dpi ]; then
   if [ -n "$(ls -l /usr/lib/X11/fonts/75dpi/helv*.Z)" ]; then
      if [ -n "$(ls -l /usr/lib/X11/fonts/75dpi/tim*.Z)" ]; then
        if [ -n "$(ls -l /usr/lib/X11/fonts/75dpi/ncen*.Z)" ]; then
                checkForAppFiles
                processit
        fi
      fi
# They have some helvetica font so let the user continue
      checkForAppFiles
      processit
   fi
fi
echo '\007'
echo 'Cfg Error : The X11 font files for Helvetica, Times and New
CenturySchoolbook'
echo '  could not be found in the X11 font directory /usr/lib/X11/fonts/75dpi.
 Please'
echo '  install these fonts before trying to run the Configuration
Program.'
exit 1
